#pragma once
#ifndef _BASE_THREAD_H_
#define _BASE_THREAD_H_
#ifdef WIN32
#pragma execution_character_set("utf-8")
#endif // WIN32

#include <QObject>
#include <QThread>
#include <QProcess>
#include <QMutex>
#include <QWaitCondition>
#include <QDebug>
#include "MyModel.h"
#include "MyError.h"
#include "utils.h"

class BaseThread : public QThread {
	
	Q_OBJECT

public:

	BaseThread(QObject* parent = nullptr);

	~BaseThread();

	/// <summary>
	/// 唤醒线程
	/// </summary>
	void resume();

	/// <summary>
	/// 线程暂停/挂起
	/// </summary>
	void pause(int timeout = 0);

	/// <summary>
	/// 停止线程
	/// </summary>
	void stop();

	/// <summary>
	/// 启动线程
	/// </summary>
	/// <param name="pri"></param>
	void start(Priority pri = InheritPriority);

	/// <summary>
	/// 线程是否在运行
	/// </summary>
	/// <returns></returns>
	bool isRunning();

	/// <summary>
	/// 线程是否挂起
	/// </summary>
	/// <returns></returns>
	bool isHangUp();

	/// <summary>
	/// 判断线程是否已经停止运行
	/// </summary>
	/// <returns></returns>
	bool isStop();

private:

	std::atomic_bool m_pauseFlag;		//标志线程暂停

	std::atomic_bool m_stopFlag;		//标志线程停止

	QMutex m_mutex;

	QWaitCondition m_condition;		//挂起/唤醒线程
};



#endif // !_BASE_THREAD_H_



